package com.gitee.aurora.dao.impl;

import com.gitee.aurora.comm.AuroraJdbcTemplate;
import com.gitee.aurora.dao.DataCheckDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * author: jiangfuxiao
 * Date:2022/9/2 11:47
 */
@Repository("dataCheckDaoImpl")
public class DataCheckDaoImpl implements DataCheckDao {

    @Autowired
    private AuroraJdbcTemplate auroraJdbcTemplate;



    @Override
    public String queryCodeList(String code) {
        List<String> codes = new ArrayList<>();
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT                                               ");
        sql.append(" GROUP_CONCAT(T1.S_CODE SEPARATOR ',')   AS  S_CODE  ");
        sql.append(" FROM TAB_ORG_ZFJD T1                             ");
        sql.append(" LEFT JOIN TAB_ORG_ZFJD T2 ON T1.S_PATH LIKE CONCAT( T2.S_PATH, '%') ");
        sql.append(" WHERE  1=1                                          ");
        sql.append(" AND T2.S_CODE = ").append(code);
        try {
            codes = auroraJdbcTemplate.queryForMapToUpperCaseList(sql.toString(), String.class);
        }catch (Exception e){
            e.printStackTrace();
        }
        if (CollectionUtils.isEmpty(codes)){
            return "";
        }
        return codes.get(0);
    }
}
